package com.ws.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.SqlReturnResultSet;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ws.bean.Customer;
import com.ws.common.CommonResult;
import com.ws.service.CustomerService;
import com.ws.util.Page;

@RestController
@RequestMapping("customer")
public class CustomerController {
	@Autowired
	CustomerService service;
	@GetMapping("select")
	public CommonResult getCustomer(Customer customer , Page page) {
		List<Customer> list = service.getCustomer(customer , page);
		int count = service.getCount(customer);
		Map map = new HashMap<>();
		map.put("list", list);
		map.put("count", count);
		return CommonResult.success(map);
	}
	@DeleteMapping("del/{id}")
	public CommonResult delCustomer(@PathVariable Integer id){
		int result = service.delCustomer(id);
		return CommonResult.success();
	}
	@PutMapping("edit")
	public CommonResult editCustomer(Customer customer) {
		int result = service.editCustomer(customer);
		return CommonResult.success();
	}
	
	@PostMapping("add")
	public CommonResult addCustomer(@RequestBody Customer customer) {
		int result = service.addCustomer(customer);
		return CommonResult.success();
	}
}
